package site.teamo.biu.flink.web.util;

import site.teamo.biu.flink.web.controller.model.BiuJSONResult;
import site.teamo.biu.flink.web.exception.BiuResponseCode;


public final class BiuJSONResultUtils {

    private static final int OK_CODE = 0;
    private static final String OK_MSG = "ok";

    private BiuJSONResultUtils() throws IllegalAccessException {
        throw new IllegalAccessException("BiuJSONResultUtils does not support instantiation");
    }

    private static final BiuJSONResult OK = new BiuJSONResult()
            .setCode(OK_CODE)
            .setMsg(OK_MSG);

    public static BiuJSONResult ok() {
        return OK;
    }

    public static BiuJSONResult ok(Object data) {
        return new BiuJSONResult()
                .setCode(OK_CODE)
                .setMsg(OK_MSG)
                .setData(data);
    }

    public static BiuJSONResult error(BiuResponseCode code) {
        return new BiuJSONResult()
                .setCode(code.code)
                .setMsg(code.msg);
    }

    public static BiuJSONResult error(BiuResponseCode code, String msg) {
        return new BiuJSONResult()
                .setCode(code.code)
                .setMsg(msg);
    }

    public static BiuJSONResult error(int code, String msg) {
        return new BiuJSONResult()
                .setCode(code)
                .setMsg(msg);
    }

    public static BiuJSONResult error(BiuResponseCode code, Object data) {
        return new BiuJSONResult()
                .setCode(code.code)
                .setMsg(code.msg)
                .setData(data);
    }
}
